/**
 * Created by Administrator on 2016/7/31 0031.
 */
$(function () {
    $("#projectTop").show();
    $("#projectTable").show();
    $("#setTop").hide();
    $("#setFrom").hide();
    studentGetAll();
    bindSee();
});
function bindSee() {
    $(".see").click(function () {
        var dataSee = {};
        dataSee.flag="see"
        dataSee.projectID=$(this).parent().parent().children(".id").text();
        var url = "/TaskCollection/Project/project.wst";
        $.post(url,dataSee,function (result) {
            if(result.project!=null){
                $("#projectTop").hide();
                $("#projectTable").hide();
                $("#setTop").show();
                $("#setFrom").show();
                $("#name span").text(result.project.project_name);
                $("#student span").text(result.project.student.student_name);
                $("#introduction textarea").text(result.project.project_introduction);
                $("#type span").text(result.project.projectClassify.projectClassify_name);
                bindset_enter_back(result);
            }
        },"json")
    });
}
function bindset_enter_back(lastresult) {
    $("#set-enter").click(function () {
        //self.location='/TaskCollection/student/homepage.jsp'
        var datajoin = {};
        datajoin.flag="join";
        datajoin.projectTeamID=lastresult.project.projectTeam.projectTeam_id;
        var url = "/TaskCollection/StudentProjectTeam/studentProjectTeam.wst";
        $.post(url,datajoin,function (result) {
            if(result.msg==true){
                self.location='/TaskCollection/student/projectTeam.jsp?id='+datajoin.projectTeamID;
            }else if(result.msg==false){
                alert("加入失败，请重试！");
            }else{
                alert("加入失败，你已经加入"+result.msg.projectTeam.projectTeam_name);
            }
        },"json");
    });
    $("#set-back").click(function () {
        $("#projectTop").show();
        $("#projectTable").show();
        $("#setTop").hide();
        $("#setFrom").hide();
    });
}
function studentGetAll() {
    var dataall = {};
    dataall.flag="studentGetAll";
    var url = "/TaskCollection/Project/project.wst";
    $.ajaxSetup({
        async : false
    });
    $.post(url,dataall,function (result) {
        for(var i=0;i<result.studentGetAll.length;i++){
            var newrow = "<tr>" +
                "<td class='id'>"+result.studentGetAll[i].project_id+"</td>" +
                "<td>"+result.studentGetAll[i].project_name+"</td>" +
                "<td>"+result.studentGetAll[i].student.student_name+"</td>" +
                "<td id='projectTeam'><a href='javascript:void(0)'>"+result.studentGetAll[i].projectTeam.projectTeam_name+"</a></td>" +
                "<td>"+result.studentGetAll[i].projectClassify.projectClassify_name+"</td>" +
                "<td><input class='btn see' type='button' value='查看详情'></td> " +
                "</tr>";
            $("#project tr:last").after(newrow);
            bindProjectTeam()
        }
    },"json");
}
function bindProjectTeam() {
    $("#projectTeam").click(function () {
        var id = $(this).parent().children(".id").text();
        self.location='/TaskCollection/student/projectTeam.jsp?id='+id;
    });
}
